package testPackage.testPackage;
/**
 * step by step 3-1 自动化操作网页的过程
 */

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

/* import static java.lang.Thread.sleep; */

public class Selenium04 {
    public static void main(String[] args) throws InterruptedException {
        //设置启动器路径
        System.setProperty("webdriver.chrome.driver","D:\\\\Enviroments\\\\geckodriver-v0.26.0-win64\\\\chromedriver.exe");
        //创建、初始化并启动浏览器的启动器对象
        WebDriver driver = new ChromeDriver();
        //等待10s
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //打开网页
        driver.get("https://www.baidu.com");
        //获取一个web元素的文本信息
        driver.findElement(By.id("kw")).sendKeys("淘宝");
        String sampleText = driver.findElement(By.id("kw")).getText();
        System.out.println(sampleText);
        //等待3s
        Thread.sleep(3000);
        //点击一个元素
       // driver.findElement(By.className("btn self-btn bg s_btn")).click();
       // Thread.sleep(3000);
        driver.get("https://www.taobao.com/");
        //定位一个textBox并设置文本框中信息
        driver.findElement(By.id("q")).sendKeys("JMeter");
        Thread.sleep(3000);
        //清除文本框中信息
        driver.findElement(By.id("q")).clear();
        Thread.sleep(3000);
        //通过id获取定位元素
        driver.findElement(By.id("dg-item-tl-2")).click();
        Thread.sleep(10000);
        driver.navigate().back();
        //关闭浏览器
        driver.close();
    }
}
